/*  
cd /projects/hsieh_ra/import/
qsas 06_aux_pull.sas 8 &

Author: Adarsh Kumar

Objective: Import auxiliaries
*/
/*REDACTED 
Comment describing the aux data being imported and other relevant notes are redacted */

libname buildr "/projects/data_p/build/raw/";
%Let dir_buildr = /projects/data_p/build/raw/;

/* REDACTED 
aux has been renamed to REDACTED to avoid disclosing location of raw file */
libname aux "/REDACTED/";
/* REDACTED
Comment on aux data structure redacted */

/* REDACTED 
aux has been renamed to REDACTED to avoid disclosing location of raw file
raw file names (after "set" command) also redacted
*/

/* REDACTED
Please note that pseudonyms are used instead of variable names used in raw data. This is done
to abide by Census disclosure guidelines. If authorized to access by Census, one can access researchers' 
concordance saved in the Census RDC lan. */ 

libname aux "/REDACTED/";
data aux_1977(keep = cennum yr tnum alnum msa1 cty1 st1 final_emp1 final_sales1 final_salaries1); 
  set aux.aux1977; 
  year = 1977; 
run; 

libname aux "/REDACTED/";
data aux_1982(keep = cennum yr tnum alnum msa1 cty1 st1 final_emp1 final_sales1 final_salaries1); 
  set aux.REDACTED; 
  year = 1982; 
run; 

libname aux "/REDACTED/";
data aux_1987(keep = cennum yr tnum alnum msa1 cty1 st1 zipcode1 final_emp1 final_sales1 final_salaries1); 
  set aux.REDACTED; 
  rename final_emp2=final_emp1; 
  rename final_sales2=final_sales1; 
  rename final_salaries2=final_salaries1;
  rename cty2=cty1;
  year = 1987; 
run; 

libname aux "/REDACTED/";
data aux_1992(keep = cennum yr tnum msa1 cty1 st1 zipcode1 final_emp1 final_sales1 final_salaries1);
  set aux.REDACTED; 
  rename final_emp3=final_emp1;
  rename final_sales3=final_sales1;
  rename final_salaries3=final_salaries1;
  rename cty2=cty1;
  year = 1992; 
run; 

libname aux "/REDACTED/";
data aux_1997(keep= cennum yr tnum msa1 cty1 st1 zipcode1 final_emp1 final_sales1 final_salaries1); 
  set aux.REDACTED; 
  rename final_sales4=final_sales1;
  rename final_salaries4=final_salaries1; 
  rename final_emp4=final_emp1; 
  rename msa2=msa1;
  rename cty3=cty1;
  rename st2=st1;
  rename zipcode2=zipcode1;
  year = 1997; 
run; 

/* Append */

data aux_append; 
  set aux_1977 aux_1982 aux_1987 aux_1992 aux_1997; 
  rename msa1=msa_cen; 
  rename cty1=COUNTY_FIPS; 
  rename st1=STATE_FIPS; 
  zip_cen = substr(zipcode1,1,5);
  zip_cen=zip_cen*1;
  rename final_emp1=final_emp;
  rename final_sales1=final_sales;
  rename final_salaries1=final_salaries;
run;

data buildr.aux_appended; 
  set aux_append; 
run; 

proc export data = aux_append outfile = "&dir_buildr./aux_appended.dta" replace; run;
